---
- name: Include OS-specific variables.
  include_vars: "{{ ansible_os_family }}.yml"

- name: Define ruby_packages.
  set_fact:
    ruby_packages: "{{ __ruby_packages }}"
  when: ruby_packages is not defined

# Include OS-specific installation tasks.
- include_tasks: setup-RedHat.yml
  when:
    - not ruby_install_from_source
    - ansible_os_family == 'RedHat'

- include_tasks: setup-Debian.yml
  when:
    - not ruby_install_from_source
    - ansible_os_family == 'Debian'

# Install ruby from source when ruby_install_from_source is true.
- include_tasks: install-from-source.yml
  when: ruby_install_from_source

- name: Add user installed RubyGems bin directory to global $PATH.
  copy:
    src: rubygems.sh
    dest: /etc/profile.d/rubygems.sh
    mode: 0644

# Install Bundler and configured gems.
- name: Install Bundler.
  gem: name=bundler state=present user_install=no
  when: ruby_install_bundler

- name: Install configured gems.
  gem:
    name: "{{ item }}"
    state: present
  become: true
  become_user: "{{ ruby_install_gems_user }}"
  with_items: "{{ ruby_install_gems }}"
